package com.jinlia.show.modules.wxapp.controller;

import com.alibaba.fastjson.JSONObject;
import com.jinlia.show.common.core.utils.UserInfoUtils;
import com.jinlia.show.modules.base.model.po.PayOrderPO;
import com.jinlia.show.modules.base.system.entity.MemberCardBalanceChange;
import com.jinlia.show.modules.base.wxapp.entity.PayOrder;
import com.jinlia.show.modules.wxapp.service.PayService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 付款单
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/payOrder")
public class PayOrderController {

    @Autowired
    private PayService payService;

    @GetMapping("/by/saleOrder/{id}")
    public ResponseEntity<PayOrder> payBySaleOrder(@PathVariable("id") Long saleOrderId) {
        return ResponseEntity.ok(payService.payBySaleOrder(saleOrderId));
    }

    @PostMapping("todo")
    public ResponseEntity<List<PayOrder>> getTodoList(@RequestBody PayOrder payOrder) {
        payOrder.setUserId(UserInfoUtils.getUserId());
        return ResponseEntity.ok(payService.getTodoList(payOrder));
    }

    /**
     * 支付提交
     *
     * @param payOrderPO
     * @return 微信支付码
     */
    @PostMapping("paySubmit")
    public ResponseEntity<PayOrder> paySubmit(@RequestBody PayOrderPO payOrderPO) {
        return ResponseEntity.ok(payService.paySubmit(payOrderPO));
    }
    /**
     * 微信付款预支付
     *
     * @param payOrderId 付款单id
     * @return
     */
    @GetMapping("/pre/{payOrderId}")
    public ResponseEntity<JSONObject> payPre(@PathVariable("payOrderId") Long payOrderId) {
        return ResponseEntity.ok(payService.payPre(payOrderId));
    }

    /**
     * 会员充值预支付
     *
     * @param id 充值折扣id
     * @return
     */
    @GetMapping("/pre/recharge/{id}")
    public ResponseEntity<JSONObject> payPreRecharge(@PathVariable("id") Long id) {
        return ResponseEntity.ok(payService.payPreRecharge(id));
    }

    /**
     * 模拟支付成功
     * 余额充值成功
     *
     * @param id
     * @return
     */
    @GetMapping("recharge/success/{id}")
    public ResponseEntity<MemberCardBalanceChange> payMemberBalance(@PathVariable("id") Long id) {
        return ResponseEntity.ok(payService.payMemberBalance(id));
    }

}
